package com.jeesite.modules.stock.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jeesite.modules.stock.dao.mapper.UserStocksMapper;
import com.jeesite.modules.stock.entity.UserStockEntity;

@Component
public class UserStocksDao {
	
	@Autowired
	private UserStocksMapper userStocksMapper;
	
	public void insert(UserStockEntity entity) {
		userStocksMapper.insert(entity);
	}
	
	public void update(UserStockEntity entity) {
		userStocksMapper.update(entity);
	}
	
	public void updatePageName(String pageId, String pageName) {
		userStocksMapper.updatePageName(pageName, pageId);
	}
	
	public void deleteById(String id) {
		UserStockEntity entity = new UserStockEntity();
		entity.setId(id);
		userStocksMapper.delete(entity);
	}
	
	public List<Map<String, Object>> findUserPageStockList(String userId, String pageName) {
		UserStockEntity entity = new UserStockEntity();
		entity.setUserId(userId);
		entity.setPageName(pageName);
		return searchUserPageStocks(entity);
	}
	
	public boolean exist(String userId, String pageName, String stockCode) {
		UserStockEntity entity = new UserStockEntity();
		entity.setUserId(userId);
		entity.setPageName(pageName);
		entity.setStockCode(stockCode);
		
		return userStocksMapper.findCount(entity)>0;
	}
	
	public List<Map<String, Object>> searchUserPageStocks(UserStockEntity entity) {
		return userStocksMapper.searchUserPageStocks(entity);
	}
	
	public void deleteUserStock(UserStockEntity entity) {
		userStocksMapper.deleteUserStock(entity);
	}
	
	public void deleteUserStockOfPageName(String userId, String pageName) {
		UserStockEntity entity = new UserStockEntity();
		entity.setUserId(userId);
		entity.setPageName(pageName);
		deleteUserStock(entity);
	}
	
	public int getUserPageStockCount(String userId, String pageName) {
		UserStockEntity entity = new UserStockEntity();
		entity.setUserId(userId);
		entity.setPageName(pageName);
		return (int) userStocksMapper.findCount(entity);
	}
}
